/**
 * @(#)com.framework.web.wechat.util.ExpressUtil
 *
 * Copyright (c) 2014-2018 一抹风光
 *
 * DESC:
 *
 */
package com.framework.web.wechat.util;

import com.framework.web.wechat.domain.ExpressResponse;
import net.sf.json.JSONObject;
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * @author fusf
 * @version 1.0  2016/11/20
 */
public class ExpressUtil {


    public static ExpressResponse getExpressResponse(String com, String nu) {
        String host = "http://ali-deliver.showapi.com";
        String path = "/showapi_expInfo";
        String method = "GET";
        Map<String, String> headers = new HashMap<String, String>();
        //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
        headers.put("Authorization", "APPCODE e90895d84d55421890bd957bad56560a");
        Map<String, String> querys = new HashMap<String, String>();
        querys.put("com", com);
        querys.put("nu", nu);

        try {
            /**
             * 重要提示如下:
             * HttpUtils请从
             * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java
             * 下载
             *
             * 相应的依赖请参照
             * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
             */
            HttpResponse response = HttpUtils.doGet(host, path, method, headers, querys);
            //System.out.println(response.toString());
            //获取response的body
            //System.out.println(EntityUtils.toString(response.getEntity()));
            JSONObject jsonobject = JSONObject.fromObject(EntityUtils.toString(response.getEntity()));
            ExpressResponse expressResponse = (ExpressResponse) JSONObject.toBean(jsonobject,
                    ExpressResponse.class);
            return expressResponse;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public static void main(String[] args) {
       ExpressResponse response=  getExpressResponse("shunfeng", "611182007566");
        System.out.println(response.toString());
    }

}
